﻿using System;
using System.Diagnostics.Contracts;
using AutomaTones.Model.Automaton_Model;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.MIDI {
    /// <summary>
    /// The colors that the pads on the Launchpad can have. 
    /// Values in this enum represents the actual values that the Launchpad understands.
    /// </summary>
    /// <author>Anders Bech Mellson, anbh@itu.dk</author>
    public enum PadColor {
        DimGreen = 28,
        FullGreen = 60,
        DimAmber = 29,
        FullAmber = 63,
        Yellow = 62,
        DimRed = 13,
        FullRed = 15,
        Off = 12
    } ;

    /// <summary>
    /// Class that can convert between states and Padcolor.
    /// </summary>
    /// <author>Anders Bech Mellson, anbh@itu.dk</author>
    internal class LaunchpadModel {
        /* Holds the color for each state. State 0 = off, state 1 = Full Red eg.
         * Both 0, 7 holds off.
         * This was done to match a design decision to have 8 states.
         * However the Launchpad only actually have 7 states. So the off state is reused.
         */
        public static int[] StateToColor = {
                                     12, //Off
                                     15, //Full Red
                                     13, //Dim Red
                                     63, //Full Amber
                                     29, //Dim Amber
                                     60, //Full Green
                                     28, //Dim Green
                                     12 //Off
                                 };

        /// <summary>
        /// Send a state you wish to convert to a Padcolor.
        /// </summary>
        /// <param name="state">State to be converted to a Padcolor.</param>
        /// <returns>Padcolor.</returns>
        [PexMethod]
        public static PadColor ConvertStateToColor(State state) {
            Contract.Requires(state.CurrentState >= 0 && state.CurrentState <= 7);
            return (PadColor) StateToColor[state.CurrentState];
        }
    }
}
